/*
	@desc  定时器控制数字增长
	@date 20140518
	@author LiWang112358
*/
#include <reg52.h>

#define MAXCNT 1000
#define DELAY_LEN 100
int cnt = 0;
sbit Ac = P2^7;
sbit Bc = P2^0;

int delay(int x)
{
	int i;
	for (i = 0; i < x; ++ i);
	return 0;
}

int init_timer()
{
    TMOD |= 0x01;
    TH0 = 0x00;
    TL0 = 0x00;
    EA = 1;
    ET0 = 1;
    TR0 = 1;
}

int func2(int tmp[])
{
	static unsigned char code table[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
	int i;
	for (i = 0; i < 8; ++ i){	
		P0 = ~(1<<i);
		Ac = 1;
		Ac = 0;
		P0 = ~table[tmp[i]];
		Bc = 1;
		Bc = 0;
		delay(DELAY_LEN);
	}
	return 0;
}

int shownum(int x)
{
	int i;
	int tmp[8] = {0};
	i = 7;
	while(x && i >= 0){
		tmp[i] = x % 10;
		x /= 10;
		i -= 1;
	}
	func2(tmp);
	return 0;
}

void timer_callback(void) interrupt 1
{
    TH0 = 0x00;
    TL0 = 0X00;
	if (cnt > MAXCNT) {
		cnt = 0;
	} else {
		++ cnt;
	}
}

int main()
{
	init_timer();
	while(1) {
		shownum(cnt);
		delay(DELAY_LEN);
	}
	return 0;
}